package org.fuys.coder.infrastructure.repository;

import org.fuys.coder.domain.auth.repository.ICaptchaRepository;
import org.fuys.coder.infrastructure.util.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.infrastructure.repository
 * @className: CaptchaRepository
 * @author: WangJing
 * @description: 验证码仓储
 * @date: 2024/9/6 15:42
 * @version: 1.0
 */

@Service
public class CaptchaRepository implements ICaptchaRepository {

    @Resource
    private RedisUtil redisUtil;

    @Override
    public void saveCaptcha(String key, String value) {
        redisUtil.commonSet(key,value);
        redisUtil.expire(key,5, TimeUnit.MINUTES);
    }

    @Override
    public String getCaptcha(String key) {
        return redisUtil.commonGet(key).toString();
    }

    @Override
    public void deleteCaptcha(String key) {
        redisUtil.deleteKey(key);
    }
}
